package com.zmn.plat.services.impl.base.city.ratio;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.zmn.plat.model.entity.base.city.ratio.BaseCityRatio;
import com.zmn.plat.model.entity.base.city.ratio.BaseCityRatioQuery;
import com.zmn.plat.model.vo.product.BaseCityRatioVo;
import com.zmn.plat.persistence.interfaces.base.city.ratio.BaseCityRatioDao;
import com.zmn.plat.services.interfaces.base.city.ratio.BaseCityRatioService;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class BaseCityRatioServiceImpl implements BaseCityRatioService {

    @Resource
    BaseCityRatioDao baseCityRatioDao;

    @Override
    public BaseCityRatio findByKey(Integer ratioId) {
        return baseCityRatioDao.findByKey(ratioId);
    }

    @Override
    @Cacheable(cacheNames = "redis1h", key = "'base:ratio:findByRatioTypeAndCityAndCategAndBizType:priceType:'+#p0+':ratioType:'+#p1+':cityId:'+#p2+':servCategId:'+#p3+':categOneId:'+#p4+':categId:'+#p5+':bizType:'+#p6", unless = "#result == null")
    public BaseCityRatio findByRatioTypeAndCityAndCategAndBizType(Integer priceType, Integer ratioType, Integer cityId, Integer servCategId, Integer categOneId, Integer categId, Integer bizType) {
        if (priceType == null || ratioType == null  || cityId == null) {
            log.error("必填参数不能为空");
        }
        return baseCityRatioDao.findByRatioTypeAndCityAndCategAndBizType(priceType, ratioType, cityId, servCategId, categOneId, categId, bizType);
    }

    @Override
    public List<BaseCityRatioVo> listPageByQuery(BaseCityRatioQuery query) {
        int count = countByQuery(query);
        query.setTotalCount(count);
        return baseCityRatioDao.listPageByQuery(query);
    }

    @Override
    public List<BaseCityRatio> listByQuery(BaseCityRatioQuery query) {
        return baseCityRatioDao.listByQuery(query);
    }

    @Override
    public List<BaseCityRatio> listAll() {
        return baseCityRatioDao.listAll();
    }

    @Override
    public Integer countByQuery(BaseCityRatioQuery query) {
        return baseCityRatioDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(BaseCityRatio baseCityRatio) {
        return baseCityRatioDao.updateByKey(baseCityRatio);
    }

    @Override
    public void updateToBeEffectiveRatioBatch(List<BaseCityRatio> updateRatioList) {
        baseCityRatioDao.updateToBeEffectiveRatioBatch(updateRatioList);
    }

    @Override
    public Integer updateRatioByKeyBatch(List<BaseCityRatio> ratioList) {
        return baseCityRatioDao.updateRatioByKeyBatch(ratioList);
    }

    @Override
    public Integer insert(BaseCityRatio baseCityRatio) {
        return baseCityRatioDao.insert(baseCityRatio);
    }

    @Override
    public Integer insertBatch(List<BaseCityRatio> baseCityRatioList) {
        return baseCityRatioDao.insertBatch(baseCityRatioList);
    }

    @Override
    public Integer deleteByKey(Integer ratioId) {
        return baseCityRatioDao.deleteByKey(ratioId);
    }

    @Override
    public Integer deleteByKeys(List<Integer> ratioIds) {
        return baseCityRatioDao.deleteByKeys(ratioIds);
    }
}